// pages/qiye_jieshao/qiye_jieshao.js
const app = getApp()
//获得全局js变量
var util = require('../../utils/util.js');
// orderList.js
Page({
  data: {
    isShow: true,
    loadingType: 0,
    keywords: '',
    year: '',
    month: '',
    userinfo: [],
    list: [],
    allnum: '',
    ispLayer: false,
    pass: '',
    sureOrderId: 0
  },

  onLoad(options) {
    const date = new Date();
    this.setData({
      year: date.getFullYear(),
      month: date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
    });
    wx.setNavigationBarTitle({
      title: '全部订单'
    });
    this.setData({
      id: options.id,
      userinfo: wx.getStorageSync('user')
    });
    this.getinfo();
  },

  onInput(e) {
    this.setData({
      keywords: e.detail.value
    });
    this.getinfo();
  },

  onPassInput(e) {
    this.setData({
      pass: e.detail.value
    });
  },

  bindDateChange: function(e) {
    var date = e.detail.value;
    var arr = date.split('-');
    this.setData({
      year: arr[0],
      month:arr[1]
    })

    this.getinfo();
  },
  getinfo() {
    const that = this;
    util.httpRrquest(app.data.apiurl + 'shop/getOrderTongji', 'GET', {id: that.data.id,
        keywords: that.data.keywords,
        month: that.data.month,
        year: that.data.year})
    .then(function (response) {
        var list=response.data.data;
        that.setData({
          info: list.info,
          allnum: list.allnum,
          list: list.list
        });
    }, function (error) {
        console.log(error);
    });
  },

  hexiao(e) {
    const id = e.currentTarget.dataset.id;
    this.setData({
      sureOrderId: id,
      ispLayer: true
    });
  },

  closep() {
    this.setData({
      ispLayer: false
    });
  },

  surepass() {
    if (!this.data.pass) {
      wx.showToast({
        icon: 'none',
        title: '请输入核销码'
      });
      return;
    }
    const that = this;
    util.httpRrquest(app.data.apiurl + 'shop/orderSure', 'GET', {pass: this.data.pass,
        sureOrderId: this.data.sureOrderId})
    .then(function (response) {
        that.getinfo();
    }, function (error) {
        console.log(error);
    });

    
  }
});